<div id="mod_function_{{each_function.unique_id}}">
  <form id="mod_function_form" method="post" action="/function">
    {{form_conditional.csrf_token}}
    {{form_conditional.function_id(value=each_function.unique_id)}}
    {{form_conditional.function_type(value='trigger')}}

    <div class="row small-gutters" style="padding: 0.3em 0.2em 0.3em 0.3em;">
      <div class="col-auto">
        <button type="button" class="form-control btn btn-primary btn-sm btn-block" data-dismiss="modal">{{_('Close')}}</button>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).processRequest(this, 'function_mod');" name="function_mod" value="{{_('Save')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
      <div class="col-auto">
        <input onclick="return confirm('{{_('Are you sure you want to delete this?')}}') && $(this).processRequest(this, 'function_delete');" name="function_delete" value="{{_('Delete')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).processRequest(this, 'execute_all_actions');" name="execute_all_actions" value="{{_('Execute All Actions')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
    </div>

    {% if each_function.trigger_type in function_info and 'message' in function_info[each_function.trigger_type] %}
    <div class="row small-gutters" style="padding: 0.3em 0.2em 0.3em 0.3em;">
      <div class="col-12">
        {{function_info[each_function.trigger_type]['message']}}
      </div>
    </div>
    {% endif %}

    <div id="return_text_{{each_function.unique_id}}" class="col-12"></div>

    <div class="row small-gutters" style="padding: 0.3em 0.2em 0.3em 0.3em;">
      <div class="col-auto">
        {{form_trigger.name.label(class_='control-label')}}
        <div>
          {{form_trigger.name(class_='form-control', value=each_function.name, **{'title': dict_translation['name']['phrase']})}}
        </div>
      </div>

  {% if each_function.trigger_type == 'trigger_output' %}
    {% include 'pages/function_options/trigger_options/output.html' %}
  {% elif each_function.trigger_type == 'trigger_output_pwm' %}
    {% include 'pages/function_options/trigger_options/output_pwm.html' %}
  {% elif each_function.trigger_type == 'trigger_edge' %}
    {% include 'pages/function_options/trigger_options/edge.html' %}
  {% elif each_function.trigger_type == 'trigger_run_pwm_method' %}
    {% include 'pages/function_options/trigger_options/run_pwm_method.html' %}
  {% elif each_function.trigger_type == 'trigger_sunrise_sunset' %}
    {% include 'pages/function_options/trigger_options/sunrise_sunset.html' %}
  {% elif each_function.trigger_type == 'trigger_timer_daily_time_point' %}
    {% include 'pages/function_options/trigger_options/timer_daily_time_point.html' %}
  {% elif each_function.trigger_type == 'trigger_timer_daily_time_span' %}
    {% include 'pages/function_options/trigger_options/timer_daily_time_span.html' %}
  {% elif each_function.trigger_type == 'trigger_timer_duration' %}
    {% include 'pages/function_options/trigger_options/timer_duration.html' %}
  {% endif %}

      <div class="col-auto">
        {{form_trigger.log_level_debug.label(class_='control-label')}}
        <div class="input-group-text">
          <input id="log_level_debug" name="log_level_debug" type="checkbox" title="{{dict_translation['log_level_debug']['phrase']}}" value="y"{% if each_function.log_level_debug %} checked{% endif %}>
        </div>
      </div>

    </div>

  </form>

  <div class="row align-items-end small-gutters" style="border-top: 1px solid #ddd; padding-top: 0.5em">
    <h5>{{_('Actions')}} <a href="https://kizniche.github.io/Mycodo/Actions" target="_blank"><span style="font-size: 16px" class="fas fa-question-circle"></span></a></h5>
  </div>

  <form method="post" action="/function">
    {{form_actions.csrf_token}}
    {{form_actions.device_id(class_='form-control', value=each_function.unique_id)}}
    {{form_actions.function_type(class_='form-control', value='trigger')}}

    <div class="row align-items-end small-gutters" style="padding: 0.5em 0 0.2em 1em">
      <div class="col-auto">
        <select class="selectpicker" data-live-search="true" title="{{_('Action')}}: {{dict_translation['select_one']['title']}}" id="action_type_{{each_function.unique_id}}" name="action_type">
        {% for value, name in choices_actions %}
          <option value="{{value}}">{{name}}</option>
        {% endfor %}
        </select>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).processRequest(this, 'add_action');" name="add_action" value="{{_('Add')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
    </div>
  </form>

  {% set post_action = "/function" %}

  <div id="mod_function_actions_{{each_function.unique_id}}">
    <div class="row small-gutters" style="border-bottom: 1px solid #ddd; padding: 0.3em">
      <div class="col-12">
        <strong>Usage:</strong>: When the controller is triggered, each Action will be executed.
      </div>
    </div>
  {% for each_action in action if each_action.function_id == each_function.unique_id %}
    {% include 'pages/actions.html' %}
  {% endfor %}
  </div>

</div>
